package display;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.Timer;




public class Display extends JPanel{

	
/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
/**
 * Provides basic functions for LED 8x8 Display. On real Gamepad all this methods are native
 * 
 *
 * @author Tavin
 * @version 1.0
 */

	

public static final int xSize = 8;
public static final int ySize = 8;


static RGBColor  displayArea[][]=new RGBColor [xSize] [ySize];	
	
private static Canvas_Display myCanvas =new Canvas_Display(displayArea);

public Display()
{

clear(new RGBColor(0,0,0));	
	
//setLayout(null);
buildPanel();	
setSize(400,400);
}




private void buildPanel()
{
	//myCanvas =new Canvas_Display(displayArea);
		
	myCanvas.setLocation(0,0);
	
	myCanvas.setSize(Canvas_Display.CellSize*Canvas_Display.CellXCount,Canvas_Display.CellSize*Canvas_Display.CellYCount);
	add(myCanvas);
	

	
	Timer periodicTimer = new Timer(50,new ActionListener()
	{
	public void actionPerformed(ActionEvent e )
		{
		repaint();
		}
	});	
	periodicTimer.start();
}

	

private static void clear(RGBColor color)
{
	int xCounter;
	int yCounter;

	
	
	for (xCounter=0;xCounter<xSize;xCounter++)
		for (yCounter=0;yCounter<ySize;yCounter++)
		{
			displayArea[xCounter][yCounter]=color;
		}

}


public static void setPixel(int xPos,int yPos,RGBColor color)
{
if ((xPos>=0) && (yPos>=0) && (xPos<Display.xSize) && (yPos<Display.ySize))
		{
		displayArea[xPos][yPos]=color;
		}
}

public void repaint()
{
	
	myCanvas.drawPixels(myCanvas.getGraphics());	

}







}
